# 背包问题：求装入背包最大价值
def maxValue(c: float, w: list[float], v: list[float]) -> float:
    n, totalValue = len(w), 0
    for i in sorted(range(n), key=lambda i: -v[i] / w[i]):
        x = 1 if w[i] < c else c / w[i]
        totalValue += v[i] * x
        c -= w[i] * x
        if c == 0: 
            break
    return totalValue

# main
w = [20, 10, 30, 40, 10]
v = [60, 10, 120, 80, 50]
print('最大价值为:', maxValue(70, w, v))